package com.hecate.user.service.impl;

import com.hecate.common.response.HecateResponse;
import com.hecate.common.response.HecateResponse;
import com.hecate.user.api.req.role.SaveRoleReq;
import com.hecate.user.dto.role.SaveRoleDTO;
import com.hecate.user.persistence.mapper.RoleMapper;
import com.hecate.user.persistence.model.Role;
import com.hecate.user.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 黄星星
 * @date 2020-07-04
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public HecateResponse<SaveRoleDTO> saveRole(SaveRoleReq saveDepReq) {
        String name = saveDepReq.getName();
        if(StringUtils.isEmpty(name)){
            return HecateResponse.ERROR("角色名称不能为空!");
        }
        Role role = new Role();
        BeanUtils.copyProperties(saveDepReq, role);
        roleMapper.save(role);
        return null;
    }
}
